#include "comm.hpp"

//客户端--负责发消息
int main()
{
    //这里是创建共享内存
    key_t key = Getftok(PATHNAME,PROJ_ID);
    printf("value of key -> %d\n",key);
    int shmid = CreateShm(key);  //这里只需要获得shmid即可
    printf("value of shmid -> %d\n",shmid);
    //挂载共享内存
    char* start = (char*)AttachShm(shmid); //接受共享内存的起始地址
    printf("attach success %p\n",start);
    sleep(10);
    //通信的内容
    int sec=10;
    while(sec--)
    {
        printf("client say: %s\n",start);
        // struct  shmid_ds ds;
        // printf("获取属性： size: %d, pid:%d, myself: %d ,key: %d\n",ds.shm_segsz,ds.shm_cpid,getpid(),ds.shm_perm.__key);
        sleep(1);
    }


    //去关联
    DtachShm(start);
    sleep(10);
    //删除共享内存块
    Delshm(shmid);

    return 0;

}


